using MathNet;

namespace cmd
{
    public static class RandomGenerater
    {
        /// <summary>
        /// 生成正态分布随机数(示范用)
        /// </summary>
        /// <param name="mean">均值</param>
        /// <param name="stdDev">标准差</param>
        /// <returns>正态分布随机数</returns>
        public static double GenerateNormalDistribution(double mean = 0, double stdDev = 1)
        {
            var normal = new MathNet.Numerics.Distributions.Normal(mean, stdDev);
            return normal.Sample();
        }

        /// <summary>
        /// 生成三角分布随机数
        /// </summary>
        /// <param name="range">取值范围</param>
        /// <param name="mode">众数位置(0-1)，null表示取中间</param>
        /// <returns>三角分布随机数</returns>
        public static float GenerateTriangularDistribution(FloatRange range, float? mode = null)
        {
            float min = range.Range.x;
            float max = range.Range.y;
            float c = mode ?? 0.5f; // 如果mode为null，则取中间位置

            // 将mode从0-1映射到实际范围
            float actualMode = min + (max - min) * c;

            // 使用MathNet的三角分布生成随机数
            var triangular = new MathNet.Numerics.Distributions.Triangular(min, max, actualMode);
            return (float)triangular.Sample();
        }
    }
}
